package controller;

import java.io.IOException;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import dao.XxDao;

/**
 * Servlet implementation class XxUserResetPwServlet
 */
@WebServlet("/XxUserResetPwServlet")
public class XxUserResetPwServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public XxUserResetPwServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		boolean b = false; // 初始化返回值为 false
		String id = request.getParameter("id");
		String page = request.getParameter("page");
		
		// 设置响应内容类型
        response.setContentType("text/html;charset=UTF-8");
		XxDao dao = new XxDao();			
		
		//将数据写入数据库
		b=dao.updatePassword(id,"123456");
				
		//修改成功，弹出成功提示框
		if(b==true){												
			if(page.equals("1")){
				response.sendRedirect("View_xx/XxStudent.jsp");
			}else if(page.equals("2")){
				response.sendRedirect("View_xx/XxFdy.jsp");
			}else if(page.equals("3")){
				response.sendRedirect("View_xx/XxSuGuan.jsp");
			}else if(page.equals("4")){
				response.sendRedirect("View_xx/XxWy.jsp");
			}
			System.out.print("重置密码成功");
        
		}else {
			if(page.equals("1")){
				response.sendRedirect("View_xx/XxStudent.jsp");
			}else if(page.equals("2")){
				response.sendRedirect("View_xx/XxFdy.jsp");
			}else if(page.equals("3")){
				response.sendRedirect("View_xx/XxSuGuan.jsp");
			}else if(page.equals("4")){
				response.sendRedirect("View_xx/XxWy.jsp");
			}
		}
	}

}